package com.fastjars.business.spring.resolver.param;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.mvc.method.annotation.ExtendedServletRequestDataBinder;

import javax.servlet.ServletRequest;

/**
 * EmptyArgumentHandlerRequestDataBinder
 * 空参数转NULL
 * @author Brant Liu <br> 邮箱：<br>lbf1988@qq.com <br>日期：<br>2018/03/21
 * @version 1.0.0
 */
public class EmptyArgumentHandlerRequestDataBinder extends ExtendedServletRequestDataBinder {

    public EmptyArgumentHandlerRequestDataBinder(@Nullable Object target, String objectName) {
        super(target, objectName);
    }

    @Override
    protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
        super.addBindValues(mpvs, request);
        for (PropertyValue propertyValue : mpvs.getPropertyValueList()) {
            if ("".equals(propertyValue.getValue()))
                propertyValue.setConvertedValue(null);
        }
    }
}
